package cn.lxg.interceptor;

import cn.lxg.pojo.TAdmin;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg) throws Exception {
        //从session中获取对象
        TAdmin admin = (TAdmin) request.getSession().getAttribute("admin");

        // 验证管理员是否登录
        if (admin == null) {
            String loginUrl = "/page/login";
            response.sendRedirect(request.getContextPath() + loginUrl);
            return false;
        }

        return true;
    }

}
